package com.tender.service.impl;

import cn.hutool.core.lang.Assert;
import com.tender.domain.ShiroResource;
import com.tender.domain.ShiroResourceCondition;
import com.tender.domain.ShiroResourceExample;
import com.tender.service.ShiroResourceService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.tender.utils.DataUtils;

import java.util.ArrayList;
import java.util.List;

import com.tender.mapper.ShiroResourceMapper;
import org.springframework.util.CollectionUtils;

@Service
public class ShiroResourceServiceImpl implements ShiroResourceService {

    @Autowired
    private ShiroResourceMapper shiroResourceMapper;

    @Override
    public ShiroResource selectOne(ShiroResourceCondition param) {
        Assert.notNull(param.getRowId(), "资源rowId不能为空");
        ShiroResourceExample example = new ShiroResourceExample();
        ShiroResourceExample.Criteria criteria = example.createCriteria();

        DataUtils.setValueIfNotBlank(param.getResourceName(), criteria::andResourceNameEqualTo);

        List<ShiroResource> shiroResources = shiroResourceMapper.selectByExample(example);
        return CollectionUtils.isEmpty(shiroResources) ? null : shiroResources.get(0);
    }

    @Override
    public List<ShiroResource> selectList(ShiroResourceCondition param) {
        ShiroResourceExample example = new ShiroResourceExample();
        ShiroResourceExample.Criteria criteria = example.createCriteria();

        DataUtils.setListIfNotEmpty(param.getResourceRowIdList(), criteria::andRowIdIn);
        List<ShiroResource> shiroResources = shiroResourceMapper.selectByExample(example);

        return CollectionUtils.isEmpty(shiroResources) ? new ArrayList<>() : shiroResources;
    }

    @Override
    public int updateByCondition(ShiroResourceCondition param) {
        return 0;
    }

    @Override
    public int updateByPrimaryKey(ShiroResourceCondition param) {
        return 0;
    }

    @Override
    public int insertSelective(ShiroResource param) {
        return 0;
    }

    @Override
    public int insertListSelective(List<ShiroResource> params) {
        return 0;
    }

    @Override
    public int deleteByCondition(ShiroResourceCondition param) {
        return 0;
    }

    @Override
    public int deleteByPrimaryKey(Long rowId) {
        Assert.notNull(rowId, "资源rowId不能为空");
        ShiroResourceExample example = new ShiroResourceExample();
        ShiroResourceExample.Criteria criteria = example.createCriteria();
        criteria.andRowIdEqualTo(rowId);

        return shiroResourceMapper.deleteByExample(example);
    }
}
